home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Compendium Deluxe 2
/
LSD and 17bit Compendium Deluxe - Volume II.iso
/
a
/
prog
/
asmsrc
/
thesource-7.lha
/
Source
/
DefFunc.lha
/
DefFunc
/
dfopen.3
< prev
next >
Wrap
Text File
|
1993-12-14
|
5KB
|
199 lines
DEFUNC(3) C LIBRARY FUNCTIONS DEFUNC(3)
NAME
dfopen, dfclose, dfcloseall -- dynamic function constructing
and deconstructing.
SYNOPSIS
#include <defunc.h>
double (*dfopen(char* expression))(double x, double y);
int dfclose(double (*dcfnct)());
int dfcloseall(void);
DESCRIPTION
_d_f_o_p_e_n() dynamically constructs a function from an expres-
sion string passed to it. expression string is usually con-
sists of name and arguments setting information in front of
the expression body and separate with it by pseudo token
'=':
"name( arg1st, arg2nd ) = body"
On success, _d_f_o_p_e_n() will return a pointer addressing to a
global handle function. The global handle functions have
the prototype of
double hdl(double x, double y);
If the name string is a legal token name(starting with
alphabetic character and followed by alphabetic or numerical
characters), then the constructed function will be put into
the token table automatically. If the 1st argument name is
a legal token name, then the argument token name will be
reset to it( the default are "x" and "y"). Other options of
expression are:
"body" Only return the constructed function.
"(arg1st, arg2st)=" Reset the argument token names only.
"name()=body" Put function token into table.
"name = body" Put constant token into table.
"\name(arg1st, arg2nd)=" Just reset the argument token
names. The name is ignored.
"\name(arg1st, arg2nd)=body" Reset the argument token
names and return the constructed
function without put it to the token
table.
On error or the expression string doesn't generating a
defunc 1.2 Last change: 1993 1
DEFUNC(3) C LIBRARY FUNCTIONS DEFUNC(3)
function(e.g. an expression with empty body), _d_f_o_p_e_n()
returns a null pointer. There are 32 global handle functions
available. Thus, within one process, as many as 32 dynami-
cally constructed functions are allowed to coexist. The han-
dle functions can only be freed with _d_e_f_u_n_c funcions
_d_f_c_l_o_s_e() and _d_f_c_l_o_s_e_a_l_l() or end of the process.
_d_f_c_l_o_s_e() will close the dynamically constructed function
passed to it. This will free the associated global handle
function for reuse. On success, _d_f_c_l_o_s_e() return (int)0. If
this function is still in the global token table or this
function is not returned from a _d_f_o_p_e_n() call, then
_d_f_c_l_o_s_e() will not close it and return -1.
_d_f_c_l_o_s_e_a_l_l() free all handle functions which are not on the
global token table. On success call, _d_f_c_l_o_s_e_a_l_l() return the
total number of handles freed by it.
SEE ALSO
_d_e_f_u_n_c and getarguname(3), nameargu(3), namefnct(3),
namecnst(3), clrfnct(3), clrfnctall(3), clrcnst(3),
clrcnstall(3)
EXAMPLES
double (*fnctptr)();
fnctptr = dfopen("Rho(re, im) = (re*re+im*im)^0.5");
This will return a hypotenus function, change argument
tokens to "re" and "im" and put the returned function
pointer into token table with name "Rho".
double (*fnctptr)();
fnctptr = dfopen("pi = 2*asin(1)");
This will return a constant function(return valuse is a con-
stant -- 3.14159...) and add a constant token to the token
table with value 3.14159... and name "pi". As the '=' is
only a pseudo token, thus the expression
"pi = PI = 2*asin(1)"
is still unrecognizable by the _d_e_f_u_n_c
AUTHOR
Ke Jin
Physics Department
Queen's University
Kingston, Ontario
Canada K7L 3N6
jinke@sparky.phy.queensu.ca
defunc 1.2 Last change: 1993 2
DEFUNC(3) C LIBRARY FUNCTIONS DEFUNC(3)
BUGS
Report bugs of _d_e_f_u_n_c library to the author by email.
defunc 1.2 Last change: 1993 3